Skip to main content

Assigning data

Let can be used to store values in variables or define subqueries to be used in other queries (see joins)

Let for storing values

  1. Let allows you to define variables, but the variabl assingment can be done only once
let a = [1, 2, 3]  // initial assignment

// parsing error, variable 'a' is assigned multiple times
//LET a= PUSH(a, 4)

let b = push(a, 4) // allowed, result: [1, 2, 3, 4]
let c = push(b, 5) // allowed, result: [1, 2, 3, 4, 5]

return {a:a,b:b,c:c}
  1. The expected output is as follows:
  [
{
"a": [
1,
2,
3
],
"b": [
1,
2,
3,
4
],
"c": [
1,
2,
3,
4,
5
]
}
]
  1. You can also use LET to assign to a variable and sort on a specific field
//Ingore the schedule of flight, only consider unique routes (irrespective of time/schedule)
for flight in flights
LET route= {
_from: flight._from,
_to: flight._to,
UniqueCarrier: flight.UniqueCarrier,
Distance: flight.Distance
}

sort route.Distance desc

return distinct route
  1. You should see the following results (snippet):
  [
{
"_from": "airports/HNL",
"_to": "airports/EWR",
"UniqueCarrier": "CO",
"Distance": 4962
},
{
"_from": "airports/EWR",
"_to": "airports/HNL",
"UniqueCarrier": "CO",
"Distance": 4962
},
{
"_from": "airports/ATL",
"_to": "airports/HNL",
"UniqueCarrier": "DL",
"Distance": 4502
},
{
"_from": "airports/HNL",
"_to": "airports/ATL",
"UniqueCarrier": "DL",
"Distance": 4502
},
{
"_from": "airports/HNL",
"_to": "airports/ORD",
"UniqueCarrier": "UA",
"Distance": 4243
},
{
"_from": "airports/HNL",
"_to": "airports/ORD",
"UniqueCarrier": "AA",
"Distance": 4243
},
{
"_from": "airports/ORD",
"_to": "airports/HNL",
"UniqueCarrier": "AA",
"Distance": 4243
},
...
 
Help us improve

Anything unclear or buggy in this tutorial? Provide Feedback